home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / COMMON / BASE.H next >
Encoding:
C/C++ Source or Header  |  1997-04-16  |  861 b   |  53 lines

  1. /*
  2.  * a header of the basic utilities
  3.  * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  4.  */
  5.  
  6. #ifndef _BASE_H_
  7. #define _BASE_H_
  8.  
  9. #include "typedef.h"
  10.  
  11. template<class T>
  12. const T& maximum(const T& a, const T& b)
  13. {
  14.   return (a < b) ? b : a;
  15. }
  16.  
  17. template<class T>
  18. const T& minimum(const T& a, const T& b)
  19. {
  20.   return (a < b) ? a : b;
  21. }
  22.  
  23. template<class T>
  24. void swap(T& a, T& b)
  25. {
  26.   T temp = a;
  27.   a = b;
  28.   b = temp;
  29. }
  30.  
  31. template<class T>
  32. void sort2(T& a, T& b)
  33. {
  34.   if(b < a) {
  35.     swap(a, b);
  36.   }
  37. }
  38.  
  39. template<class TABLE_ELEMENT_T, class INDEX_T>
  40. uint search_info_table(const TABLE_ELEMENT_T table[], uint sentinel, INDEX_T key)
  41. {
  42.   for(int i = 0; table[i]() != sentinel; i++) {
  43.     if(table[i]() == key) {
  44.       break;
  45.     }
  46.   }
  47.   return i;
  48. }
  49.  
  50. #define M_PI 3.14159265358979
  51.  
  52. #endif /* _BASE_H_ */
  53.